#pragma once

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dctk.h" 
#include "dcmtk/ofstd/ofstd.h"
#include "dcmtk/dcmnet/dimse.h"
#include "dcmtk/dcmnet/diutil.h"
#include "dcmtk/dcmnet/dcmtrans.h"      /* for dcmSocketSend/ReceiveTimeout */
#include "dcmtk/dcmnet/dcasccfg.h"      /* for class DcmAssociationConfiguration */
#include "dcmtk/dcmnet/dcasccff.h"      /* for class DcmAssociationConfigurationFile */
#include "dcmtk/dcmdata/dcuid.h"        /* for dcmtk version name */

struct SCUParam
{
	std::string localAET;
	std::string remoteAET;
	std::string serverIP;
	int     port;
	HWND    hLogWnd;
	int     loglevel;

};

class CDcmStoreSCU
{
public:
	CDcmStoreSCU();
	~CDcmStoreSCU();

	void SetParam(SCUParam param);
	BOOL Send(std::vector<std::string>& filelist);
	BOOL Echo();

	OFBool findSOPClassAndInstanceInFile(const char *fname,
		char *sopClass,
		size_t sopClassSize,
		char *sopInstance,
		size_t sopInstanceSize);
	OFString getTransferSyntax(const char *fname);
	OFCondition addStoragePresentationContexts(T_ASC_Parameters *params, OFList<OFString> &sopClasses);
	OFBool isaListMember(OFList<OFString> &lst, OFString &s);


	/*
	* This function will read all the information from the given file,
	* figure out a corresponding presentation context which will be used
	* to transmit the information over the network to the SCP, and it
	* will finally initiate the transmission of all data to the SCP.
	*
	* Parameters:
	*   assoc - [in] The association (network connection to another DICOM application).
	*   fname - [in] Name of the file which shall be processed.
	*/
	OFCondition storeSCU(T_ASC_Association *assoc, const char *fname);

	static void progressCallback(void * callbackData, T_DIMSE_StoreProgress *progress, T_DIMSE_C_StoreRQ * req);
	
	OFCondition echoSCU(T_ASC_Association * assoc);
	OFCondition CDcmStoreSCU::addPresentationContext(T_ASC_Parameters *params, int presentationContextId,
		const OFString &abstractSyntax, const OFList<OFString> &transferSyntaxList, T_ASC_SC_ROLE proposedRole = (T_ASC_SC_ROLE)1);

	OFCondition CDcmStoreSCU::addPresentationContext(T_ASC_Parameters *params, int presentationContextId,
		const OFString &abstractSyntax, const OFString &transferSyntax, T_ASC_SC_ROLE proposedRole = (T_ASC_SC_ROLE)1);

protected:
	void log_debug(const char* fmt, ...);
	void log_info(const char* fmt, ...);
	void log_warn(const char* fmt, ...);
	void log_error(const char* fmt, ...);

private:
	SCUParam  m_param;
	int lastStatusCode;
	OFString m_firstTransferSyntax;

};

